package com.vstudy.zx.service.impl;

import com.vstudy.zx.dao.CommentsDao;
import com.vstudy.zx.entity.Article;
import com.vstudy.zx.entity.StarComments;
import com.vstudy.zx.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CommentsServiceImpl implements CommentsService {
    @Autowired
    private CommentsDao commentsDao;

    @Override
    public int star(Long te_id, Integer star, Long article_id) {
        StarComments comments = new StarComments();
        Article article = new Article();
        article.setArticle_id(article_id);
        comments.setArticle(article);
        comments.setSc_role(1);
        comments.setRole_id(te_id);
        StarComments comments2 = commentsDao.select(comments);
        if (comments2 != null) {
            comments2.setSc_level(star);
            return commentsDao.updateStar(comments2);
        } else {
            return commentsDao.addStar(comments);
        }
    }

}
